/**
 * FileName: ServerStringDecoder
 * Author:   powersi
 * Date:     2021/3/1 20:05
 * Description:
 */
package com.demo.zm.netty.sample.echo.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.string.StringDecoder;

import java.nio.charset.Charset;
import java.util.List;

/**
 * Description: 
 * Author:      powersi
 * Date:        2021/3/1 20:05
 */
@ChannelHandler.Sharable
public class ServerStringDecoder extends MessageToMessageDecoder<ByteBuf> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
        int v = msg.readInt();
        System.out.println(v);
        out.add(msg.toString(Charset.forName("utf-8")));
    }
}
